#ifndef __MY_DEFINE_H__
#define __MY_DEFINE_H__
#include "gpio.h"

#define LED(x) __HAL_TIM_SetCompare(&htim2, TIM_CHANNEL_2, x)

#define LED_R(x) __HAL_TIM_SetCompare(&htim2, TIM_CHANNEL_3, x)
#define LED_G(x) __HAL_TIM_SetCompare(&htim2, TIM_CHANNEL_4, x)

#define InfraredDetection() HAL_GPIO_ReadPin(RF_GPIO_Port, RF_Pin)
#define KEY() !HAL_GPIO_ReadPin(SW_GPIO_Port, SW_Pin)

#define MAXFLOOR 50

#define OFFLINE 50

/*灯光状态*/
enum LED_STATE
{
    OFF = 0,
    ON = 1
};
/*灯光状态*/
enum CONTROL_STATE
{
    AUTO = 0,
    REMOTE = 1,
    KEY = 2
};
#define TIMEOUT 30 //关灯延时

typedef struct
{
    /* data */
    uint16_t timeout;  //关灯延时设置
    uint16_t lowlight; //开灯环境光阈值
} FLOOR_REF;
typedef struct
{
    /* data */
    //实时输出状态
    uint8_t LightState;     //灯光状态
    uint32_t cnt;           //亮度计数
    uint16_t LightOutLevel; //灯光输出级别
    //传感器
    uint16_t AmbientLightLevel; //环境光强
    uint8_t InfraredDetection;  //红外
    uint8_t Button;
    //控制状态
    uint8_t ControlState;
    uint16_t ControlLevel;
    uint32_t ControlCnt;

} FLOOR_STATE;

/*楼层信息结构体*/
typedef struct
{
    uint8_t Look;
    uint8_t id;
    FLOOR_REF ref;
    FLOOR_STATE state;
    uint16_t maxlight;
    uint8_t dir;
} FLOOR_INFO;

typedef struct
{
    FLOOR_STATE state;
    uint32_t onlinecnt;
} OTHER_STATE;

extern FLOOR_INFO thisfloor;
extern OTHER_STATE *next_floor;
extern OTHER_STATE *last_floor;
extern OTHER_STATE otherfloor[MAXFLOOR];

void ChangeID(uint8_t newid);
void BlueTooth(uint8_t *data);
#endif
